package com.itts.common.util.result;

import com.itts.common.enums.ErrorEnum;

import java.util.HashMap;
import java.util.Map;

public class R extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public R() {
        put("code", 0);
        put("msg", "操作成功");
    }

    public static R error() {
        return error(500, "操作失败");
    }

    public static R error(String msg) {
        return error(500, msg);
    }

    public static R error(ErrorEnum errorEnum) {
        return error(errorEnum.getCode(), errorEnum.getMsg());
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static R ok(String msg) {
        R r = new R();
        r.put("msg", msg);
        return r;
    }

    public static R ok(Map<String, Object> map) {
        R r = new R();
        r.putAll(map);
        return r;
    }


    public static R ok() {
        return new R();
    }

    @Override
    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static R ok(String msg,Object object) {
        R r = new R();
        r.put("code", 0);
        r.put("msg", msg);
        r.put("data", object);
        return r;
    }

    public static R okData(Object object) {
        R r = new R();
        r.put("code", 0);
        r.put("msg", "操作成功");
        r.put("data", object);
        return r;
    }

    public static R loginExpired() {
        R r = new R();
        r.put("code", 405);
        r.put("msg", "登录失效");
        return r;
    }

    /**
     * 旷视人脸设备
     *
     * @return
     */
    public static String ksOk() {
        return "{\"result\":1,\"success\":ture}";
    }
}
